package com.itheima.demo1;

import java.util.Scanner;

public class Demo20Array {
    /* 1.数据类型[] 数组名；
     2.数据类型 数组名[];*/
    public static void main(String[] args) {
        //定义数组
        int[] air;
        //数据类型[] 数组名 = new 数据类型[数组的长度]
        int[] a = new int[5];
        //输出为[I@5ee12a7
        System.out.println(a);
        System.out.println();

        //静态初始化
        //标准版
        int[] air1 = new int[]{1, 2, 3};
        //简化
        int[] air2 = {1, 10, 3, 9, 7, 8, 4};
        System.out.println(air2[1]);

        //数组的遍历
        for (int i = 0; i < air2.length; i++) {
            System.out.println(air2[i]);
        }

        //数组的最值
        int max = air2[0];
        for (int i = 1; i < air2.length; i++) {
            if (air2[i] > max) {
                max = air2[i];
            }
        }
        System.out.println(max);


        //键盘录入5个整数，存储到数组中，并对数组求和
        int[] air4 = new int[5];
        Scanner sc = new Scanner(System.in);
        int sum = 0;
//        for (int i = 0; i < air4.length; i++) {
//            air4[i] = sc.nextInt();
//            sum += air4[i];
//        }
        System.out.println(sum);

        //键盘输入数据，查找索引，有返回索引值；无返回-1；
        int[] air5 = {1, 2, 3, 4, 5, 8, 9};
        while (true) {
            int num1 = -1;
            int num = sc.nextInt();
            for (int i = 0; i < air5.length; i++) {
                if (num == air5[i]) {
                    num1 = i;
                    break;
                }
            }
            System.out.println(num1);
        }
    }
}
